tools/insn-fuzz: Don't hit memcpy() for zero-length reads
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 2 Mar 2017 18:36:54 +0000 (18:36 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 6 Apr 2017 17:42:49 +0000 (18:42 +0100)
commit654740b4bd8dfb358a9cf6876e60b79395a1d1fb
treed5624c1ae2bb91a5f7b2f6a012150e85c41e7945
parent66c9436008fb4033179bdd3cda8c1dea1d469245
tools/insn-fuzz: Don't hit memcpy() for zero-length reads

For control-flow changes, the emulator needs to perform a zero-length
instruction fetch at the target offset.  It also passes NULL for the
destination buffer, as there is no instruction stream to collect.

This trips up UBSAN when passed to memcpy(), as passing NULL is undefined
behaviour per the C spec (irrespective of passing a size of 0).

Special case these fetches in fuzz_insn_fetch() before reaching data_read().

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
tools/fuzz/x86_instruction_emulator/fuzz-emul.c